package zelix.gui.clickguis.kendall.components.impls;


import net.minecraft.client.gui.FontRenderer;
import org.lwjgl.input.Keyboard;
import zelix.ManagerUtil.font.FontUtil;
import zelix.gui.clickguis.kendall.components.Component;
import zelix.hack.Hack;
import zelix.utils.hooks.visual.RenderUtils;
import zelix.utils.visual.font.FontLoaders;

import java.security.Key;

public class KendallKeyBind extends Component {


    public Hack mod;
    public KendallButton parent;

    public float x;
    public float y;
    public String KeyString;
    public boolean keybingding = false;
    public KendallKeyBind(Hack mod, KendallButton parent){
        this.mod = mod;
        this.parent = parent;
    }

    @Override
    public void render(float x,float y,int mouseX, int mouseY){
        this.x=x;
        this.y=y;

        if (keybingding){
            KeyString = "Press A KEY To Bind...";
        }else{
            KeyString = "KeyBind: " +  Keyboard.getKeyName(mod.getKey());
        }

        FontLoaders.default14.drawString(KeyString,x+10,y+20/4- FontLoaders.default14.getStringHeight(KeyString)/2,0xCCF5F5F7);
        //不要这个了




    }
    @Override
    public void mouseClicked(int mouseX, int mouseY, int mouseButton){
        float Light=x+10;
        float Top=y+20/4- FontLoaders.default14.getStringHeight(KeyString)/2;
        float Right=Light+FontLoaders.default14.getStringWidth(KeyString);
        float Bottom=Top+FontLoaders.default14.getStringHeight(KeyString);

        if (isHovered(Light,Top,Right,Bottom,mouseX,mouseY) && mouseButton == 0){
            keybingding = true;


        }
    }
    public static boolean isHovered(float x, float y, float x2, float y2, int mouseX, int mouseY) {
        if (mouseX >= x && mouseX <= x2 && mouseY >= y && mouseY <= y2) {
            return true;
        }

        return false;
    }
}
